/*
操作1根据a[0]索引的变化改p号的数值即可
操作2，根据a[0]的索引输出p号即可
操作3，记录把0号向左移动了多少次，(p-x+l)%l即可

*/

#pragma GCC optimize(2, "Ofast", "inline")
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <algorithm>
#define endl '\n'
#define int long long
#define pii pair<int, int>
#define fi first
#define se second
#define int128 __int128_t
using namespace std;
// 已知
int n, q, a[1111111];


// 未知
int t = 0;// 0号的初始位置

signed main()
{

    cin.tie(0)->ios::sync_with_stdio(false);
    cin >> n >> q;
    for (int i = 0;i < n;++i)
    {
        a[i] = i + 1;
    }
    for (int i = 0;i < q;++i)
    {
        int op, p, x;
        cin >> op >> p;
        if (op == 1)
        {
            cin >> x;
            a[(t + p - 1) % n] = x;
        }
        else if (op == 2) cout << a[(t + p - 1) % n] << endl;
        else t = (t + p % n) % n;
    }
    return 0;
}